// exports.AL_Framework_Storage_Class = void 0;
// var i = (function () {
//     function e(e, t) {
//         this._storageData = null;
//         this._originStorageData = null;
//         this.bundle = e;
//         this.localSaveKey = t;
//         this.zhixing_chushihua_chuli();
//     }
//     e.prototype.chushihua_cunchu_shuju = function (e, t) {
//         if (e) {
//             for (var o in ((this._originStorageData = e), (this._storageData = {}), e)) {
//                 var i = e[o];
//                 var n = this.shezhi_bendi_cunchu_key(o);
//                 var a = Manager.localManager.getItem(this.bundle, n, i);
//                 this._storageData[o] = a;
//                 this.hebing_shuxing(o);
//             }
//             if (t) {
//                 this.chushihua_yuancheng_key(t);
//             }
//         }
//     };
//     e.prototype.chushihua_yuancheng_key = function (e) {
//         if (e) {
//             var t = 0;
//             for (var o = e; t < o.length; t++) {
//                 var i = o[t];
//                 this.tianjia_yuancheng_key(i);
//             }
//         }
//     };
//     e.prototype.tianjia_yuancheng_key = function (e) {
//         var t = this.shezhi_bendi_cunchu_key(e);
//         var o = Manager.localManager.huoqu_cunchu_duixiang(this.bundle);
//         if (o) {
//             o.tianjia_yuancheng_key_list(t);
//         }
//     };
//     e.prototype.huoqu_yuancheng_key_list = function () {
//         var e = Manager.localManager.huoqu_cunchu_duixiang(this.bundle);
//         return e ? e.huoqu_yuancheng_key_list() : [];
//     };
//     e.prototype.huoqu_cunchu_shuju = function (e, t) {
//         if (void 0 === t) {
//             t = null;
//         }
//         var o = this.shezhi_bendi_cunchu_key(e);
//         return e in this._storageData && null != this._storageData[e]
//             ? this._storageData[e]
//             : Manager.localManager.getItem(this.bundle, o, t);
//     };
//     e.prototype.shezhi_cunchu_shuju = function (e, t) {
//         var o = this.shezhi_bendi_cunchu_key(e);
//         Manager.localManager.setItem(this.bundle, o, t);
//         this._storageData[e] = t;
//     };
//     e.prototype.reset = function () {
//         for (var e in this._originStorageData) this.shezhi_cunchu_shuju(e, this._originStorageData[e]);
//     };
//     e.prototype.hebing_shuxing = function (e) {
//         if (e) {
//             if (void 0 !== this._storageData[e]) {
//                 var t = this;
//                 Object.defineProperty(t, e, {
//                     get: function () {
//                         return t.huoqu_cunchu_shuju(e);
//                     },
//                     set: function (o) {
//                         t.shezhi_cunchu_shuju(e, o);
//                     }
//                 });
//             } else {
//                 Log.e("数据默认值不可为“undefined”，key:" + e);
//             }
//         }
//     };
//     e.prototype.shezhi_bendi_cunchu_key = function (e) {
//         return this.localSaveKey + "_" + e;
//     };
//     return e;
// })();
// exports.AL_Framework_Storage_Class = i;


exports.AL_Framework_Storage_Class = void 0;

/**
 * StorageClass类
 * 用于管理本地存储数据
 */
class AL_Framework_Storage_Class {

    /**
     * 构造函数
     * @param {string} bundle - 存储关联的bundle名称
     * @param {string} localSaveKey - 本地存储的key前缀
     */
    constructor(bundle, localSaveKey) {
        this._storageData = null;
        this._originStorageData = null;
        this.bundle = bundle;
        this.localSaveKey = localSaveKey;
        this.zhixing_chushihua_chuli();
    }

    /**
     * 初始化存储数据
     * @param {object} originData - 初始存储数据对象
     * @param {Array} remoteKeys - 远程key数组
     */
    chushihua_cunchu_shuju(originData, remoteKeys) {
        if (originData) {
            this._originStorageData = originData;
            this._storageData = {};

            for (let key in originData) {
                let originValue = originData[key];
                let localKey = this.shezhi_bendi_cunchu_key(key);
                let storedValue = Manager.localManager.getItem(this.bundle, localKey, originValue);
                this._storageData[key] = storedValue;
                this.hebing_shuxing(key);
            }

            if (remoteKeys) {
                this.chushihua_yuancheng_key(remoteKeys);
            }
        }
    }

    /**
     * 初始化远程keys
     * @param {Array} remoteKeys - 远程key数组
     */
    chushihua_yuancheng_key(remoteKeys) {
        if (remoteKeys) {
            for (let key of remoteKeys) {
                this.tianjia_yuancheng_key(key);
            }
        }
    }

    /**
     * 添加远程key
     * @param {string} key - 远程key
     */
    tianjia_yuancheng_key(key) {
        let localKey = this.shezhi_bendi_cunchu_key(key);
        let storageObj = Manager.localManager.huoqu_cunchu_duixiang(this.bundle);
        if (storageObj) {
            storageObj.tianjia_yuancheng_key_list(localKey);
        }
    }

    /**
     * 获取远程keys
     * @returns {Array} 远程key数组
     */
    huoqu_yuancheng_key_list() {
        let storageObj = Manager.localManager.huoqu_cunchu_duixiang(this.bundle);
        return storageObj ? storageObj.huoqu_yuancheng_key_list() : [];
    }

    /**
     * 获取存储数据
     * @param {string} key - 存储数据的key
     * @param {any} [defaultValue=null] - 默认值
     * @returns {any} 存储的数据
     */
    huoqu_cunchu_shuju(key, defaultValue = null) {
        let localKey = this.shezhi_bendi_cunchu_key(key);
        return (key in this._storageData && this._storageData[key] != null) ? 
            this._storageData[key] : 
            Manager.localManager.getItem(this.bundle, localKey, defaultValue);
    }

    /**
     * 设置存储数据
     * @param {string} key - 存储数据的key
     * @param {any} value - 存储的数据
     */
    shezhi_cunchu_shuju(key, value) {
        let localKey = this.shezhi_bendi_cunchu_key(key);
        Manager.localManager.setItem(this.bundle, localKey, value);
        this._storageData[key] = value;
    }

    /**
     * 重置存储数据
     */
    reset() {
        for (let key in this._originStorageData) {
            this.shezhi_cunchu_shuju(key, this._originStorageData[key]);
        }
    }

    /**
     * 合并属性
     * @param {string} key - 存储数据的key
     */
    hebing_shuxing(key) {
        if (key) {
            if (this._storageData[key] !== undefined) {
                Object.defineProperty(this, key, {
                    get: () => {
                        return this.huoqu_cunchu_shuju(key);
                    },
                    set: (value) => {
                        this.shezhi_cunchu_shuju(key, value);
                    }
                });
            } else {
                Log.e(`数据默认值不可为“undefined”，key: ${key}`);
            }
        }
    }

    /**
     * 获取本地存储key
     * @param {string} key - 原始key
     * @returns {string} 带前缀的本地存储key
     */
    shezhi_bendi_cunchu_key(key) {
        return `${this.localSaveKey}_${key}`;
    }
}

exports.AL_Framework_Storage_Class = AL_Framework_Storage_Class;
